package com.ecds.monitor;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.ecds.monitor.helper.ConnUtil;
import com.ecds.monitor.helper.SystemHelper;

public class CacheServer {

	/**
	 * 监测t_syncfile，如果有指定的local，说明有资料发布，而且缓存服务器还未同步 长时间未同步，说明系统异常
	 */
	public static void monitorSyncfile() {
		String locals = MainServer.rb.getString("monitoring.syncfile.local");
		String[] arrLocal = locals.split(",");
		String strLocal = "";
		for (int i = 0; i < arrLocal.length; i++) {
			if (!arrLocal[i].equals("")) {
				if (!strLocal.equals(""))
					strLocal += ",";
				strLocal += "\'" + arrLocal[i] + "\'";
			}
		}
		String sql = "SELECT * FROM t_syncfile WHERE local in (" + strLocal
				+ ")";
		Connection conn = null;
		try {
			conn = ConnUtil.getConn();
			Statement state = null;
			try {
				state = conn.createStatement();
				ResultSet rs = state.executeQuery(sql);
				if (rs.next()) {
					String message = MainServer.rb
							.getString("monitoring.syncfile.message");
					SystemHelper.testSendSMS(message);
				}
			} catch (SQLException e) {
				if (state != null)
					state.close();
				e.printStackTrace();
			}
		} catch (Exception e) {
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
			e.printStackTrace();
			String message = MainServer.rb
					.getString("monitoring.databese.exception");
			SystemHelper.testSendSMS(message);
		}
	}

}
